package base.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * @author jin
 * 
 */
public class sendRedirectTest extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public sendRedirectTest() {
	super();
    }

    protected void doGet(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {
	doPost(request, response);
    }

    protected void doPost(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {
	HttpSession session = request.getSession();

	synchronized (session) {
	    session.setAttribute("name", "jin");
	    session.setAttribute("name", "jeff");

	    response.setContentType("html/text");
	    //Head first書上說 可以用/sessionTest.jsp 作為參數
	    //container會將URL 加上 web context路徑，但是實測卻不行
	    // response.sendRedirect("/sessionTest.jsp"); 會出錯!!
	    response.sendRedirect("http://www.google.com.tw");

	}
    }

}
